package com.hakim.wfb.customer.util;

import com.hkfs.fundamental.common.utils.TimeUtils;
import org.apache.commons.lang3.StringUtils;
import org.joda.time.DateTime;

import java.util.Date;

/**
 * 时间方面的转化
 * Created by zhile on 2017/3/14 0014.
 */
public class DateTransferUtil {

    public static final String FORMAT_MMXDDX_HHMM = "MM月dd日 HH:mm";

    public static String transferWeekChinese(int dayOfWeek) {
        switch (dayOfWeek) {
            case 1:
                return "一";
            case 2:
                return "二";
            case 3:
                return "三";
            case 4:
                return "四";
            case 5:
                return "五";
            case 6:
                return "六";
            case 7:
                return "日";
            default:
                return null;
        }
    }

    /**
     *
     * @param date
     * @param plusDays
     * @return
     */
    public static DateTime getDateTimeByPlusDays(Date date, int plusDays) {
        return new DateTime(date).plusDays(plusDays)
                .hourOfDay().withMinimumValue()
                .minuteOfHour().withMinimumValue()
                .secondOfMinute().withMinimumValue()
                .millisOfSecond().withMinimumValue();
    }

    /**
     * 根据现在距离的天数获取截止时间
     * @param plusDays
     * @return
     */
    public static DateTime getDeadlineByPlusDays(int plusDays) {
        return getDateTimeByPlusDays(new Date(), plusDays);
    }

    /**
     * 根据距离的天数获取截止时间
     * @param plusDays
     * @return
     */
    public static Date getDeadline(int plusDays) {
        return getDeadlineByPlusDays(plusDays).toDate();
    }

    /**
     * 最近时间别名
     * @param scheduleDate
     * @return
     */
    public static String getDayAlias(String scheduleDate) {
        if (StringUtils.isNotBlank(scheduleDate)) {
            if (scheduleDate.equals(getDeadlineByPlusDays(0).toString(TimeUtils.FORMAT_YYYYMMDD))) {
                return "今天";
            } else if (scheduleDate.equals(getDeadlineByPlusDays(1).toString(TimeUtils.FORMAT_YYYYMMDD))) {
                return "明天";
            } else if (scheduleDate.equals(getDeadlineByPlusDays(2).toString(TimeUtils.FORMAT_YYYYMMDD))) {
                return "后天";
            }
        }
        return "";
    }

    /**
     * 最近时间别名
     * @param scheduleDate
     * @return
     */
    public static String getDayAlias(Date scheduleDate) {
        if (scheduleDate != null) {
            String scheduleDateString = new DateTime(scheduleDate).toString(TimeUtils.FORMAT_YYYYMMDD);
            return getDayAlias(scheduleDateString);
        }
        return "";
    }

    /**
     * 获取日期对应周末截止时间
     * @param dateTime
     * @return
     */
    public static DateTime getWeekEndTimeByDate(DateTime dateTime) {
        return new DateTime(dateTime.toString(TimeUtils.FORMAT_YYYYMMDD)).dayOfWeek().withMaximumValue().plusDays(1);
    }

    public static void main(String[] args) {
        DateTime dateTime = DateTransferUtil.getWeekEndTimeByDate(new DateTime());
        System.out.println(dateTime.toString(TimeUtils.FORMAT_YYYYMMDDHHMMSS));
        System.out.println(DateTime.now().isBefore(dateTime));
    }

}
